<template>
  <div>
    <basic-modal :modalOpt="modal" :footer="null" @closeModal="closeModal">
      <template>
        <basic-form
          :formInfos="s_FormInfo"
          :formDatas="s_formDatas"
          :rules="s_rules"
          @onSubmit="onSubmit"
          @onChangeType="onChangeType"
          @closeModal="closeModal"
        ></basic-form>
      </template>
    </basic-modal>
  </div>
</template>

<script>
import basicModal from '@/views/app/biz/common/basicModal'
import basicForm from '../common/basicForm'
import { getLicenseByPid } from '@/views/app/biz/regisLicense/regisLicense'
import { getInfoByPid, saveInfo } from './notification'
import {s_FormInfo,s_formDatas,s_rules } from './notificationConfig'


export default {
  components: {
    basicModal,
    basicForm
  },
  data() {
    return {
      loading: false,
      modal: {
        modalVisible: false,
        modalTitle: '新增发票抬头信息',
        mask:false,
        modalWidth: 'calc(100% - 307px)',
        height: 'calc(100vh - 215px)',
        dialogStyle:{ top:'40px',left:'125px'},
      },
      s_FormInfo: s_FormInfo,
      s_formDatas: s_formDatas,
      s_rules: s_rules
    }
  },
  computed: {},
  mounted() {},
  methods: {
    // 新增按钮 点击了新增
    addModal() {
      console.log('点击了新增',s_FormInfo)
      this.s_formDatas = s_formDatas
      this.modal.modalVisible = true
      this.modal.modalTitle = '新增发票抬头信息'
    },
    // 编辑按钮
    editModal(val) {
      console.log('点击了编辑')
      this.getSBypid(val)
      this.modal.modalVisible = true
      this.modal.modalTitle = '修改发票抬头信息'
    },
    // 关闭模态详细框
    closeModal() {
      this.modal.modalVisible = false
      this.$emit('close')
    },
    // 保存成功关闭模态详细框
    closeModal2() {
      this.modal.modalVisible = false
      this.$emit('ok')
    },
    // 模态详细框提交按钮
    onSubmit(val) {
      this.saveObjInfo(val)
    },
    // 保存详细信息
    async saveObjInfo(val) {
      this.loading = true
      // this.$message.loading({ content: '提交中'， })
      let res = await saveInfo(val)
      this.loading = false
      console.log(res)
      if (res && res.code && res.code === 'C1' && res.data) {
        this.$message.success({ content: '提交成功', duration: 2 })
        this.closeModal2()
      } else {
        this.$message.error({ content: '提交失败', duration: 2 })
      }
    },
    // 得到初始化信息
    async getSBypid(val) {
      let res = await getInfoByPid(val)
      if (res && res.code && res.code === 'C1') {
        if (res.data) {
          this.s_formDatas = res.data
        } else {
          this.addModal()
        }
      }
      console.log(res)
    },
    // 表单编号
    onChangeType(name, val) {
      console.log('formName', name)
      console.log('val', val)
      // switch (name) {
      //   case 'formName':
      //     // console.log('aaaaaaaaaaaaaa',name)
      //     // const zhucez = this.getZhuCezxx(val)
      //     break
      // }
    },
    restData(val) {
      this.getSBypid(this.s_formDatas.pid)
    }
  }
}
</script>

<style></style>
